package com.firemoss.atonement.test.entitymanager
{
	import com.firemoss.atonement.entitymanager.IEntityContainer;
	import com.firemoss.atonement.entitymanager.StronglyReferencedEntityContainer;
	import com.firemoss.atonement.entitymanager.WeaklyReferencedEntityContainer;
	import com.firemoss.atonement.test.metadata.inspectors.entity.objects.TestEntity;
	
	import flash.events.Event;
	import flash.events.TimerEvent;
	import flash.system.System;
	import flash.utils.Timer;
	
	import org.flexunit.asserts.*;
	import org.flexunit.async.Async;

	public class EntityContainerTests
	{		
		
		[Test]
		public function strong_container_holds_reference_to_target() : void
		{
			var container :IEntityContainer = new StronglyReferencedEntityContainer()
			var entity : TestEntity = new TestEntity()
				
			container.entity = entity
				
			entity = null;
			
			assertFalse( container.empty );
		}
		
		[Test(async)]
		public function weak_container_does_not_hold_reference_to_target() : void
		{
			var container :IEntityContainer = new WeaklyReferencedEntityContainer()
			var entity : TestEntity = new TestEntity()
			
			container.entity = entity
			
			entity = null;
			
			var timer : Timer = new Timer( 250, 1 )
			var handler : Function = Async.asyncHandler( this, weak_container_does_not_hold_reference_to_target_timerComplete, 500, { container : container } )
			timer.addEventListener( TimerEvent.TIMER, handler )
			timer.start()
			
		}
		
		private function weak_container_does_not_hold_reference_to_target_timerComplete( event : Event, data : Object ) : void
		{
			var container :IEntityContainer = data.container
			assertTrue( container.empty );
		}
		
	}
}